home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / bbs_soft / mrun210.zip / MRUN210G.WAS < prev    next >
Text File  |  1993-04-27  |  45KB  |  1,671 lines

  1. ;MailRun v2.10:  Part G, domailrun
  2. ;1992-1993 Gerald P. Sully, all rights reserved.
  3.  
  4. #COMMENT
  5. **************************************************************************
  6. **************************************************************************
  7. * The following procedures form the engine of the script.  First
  8. * makedir() is called to create a dialing directory for BBSs listed
  9. * in the *.MRN file that have pending items.  Each BBS is called,
  10. * and on connection, each pending item listed for that BBS is executed
  11. * by dobbs().  These tasks are performed by sendmail(), getmail(),
  12. * ulfile(), dlfile(), and sendcommand().  As each task is completed,
  13. * the task list window is updated.
  14. * While online, the key procedure is holding() which keeps track of the
  15. * length of time the board has been inactive, checks for dropped carrier
  16. * and obtains the current line from the terminal screen so that it can
  17. * be parsed by the various procedures that respond to prompts.  The
  18. * latter include checkbaseset(), checkcommandprompt(), checkmailprompt()
  19. * and the like.
  20. **************************************************************************
  21. **************************************************************************
  22. #ENDCOMMENT
  23.  
  24. #define MRUN210G
  25. #define MRUN210AG
  26.  
  27. #define GOTOFILE 1
  28. #define GOTOMAIN 0
  29.  
  30. string MainBoxTabs, prompt
  31. integer xferstatus, holdstatus, foundstatus
  32.  
  33. #include "mrun210.h"
  34.  
  35.  
  36. #comment
  37. *********************************************************************
  38. * MAIN()
  39. * Calls menudim(), checkchild(), maketasklist(), dobbs()
  40. * mailrunbox(), parsedialog(), makequeue(), readbbs(),
  41. * makefullname(), findstring(), capturescreen()
  42. * Main first calls the initialization routines, then puts
  43. * up the main dialog box and dispatches each requested
  44. * action.
  45. *********************************************************************
  46. #endcomment
  47.  
  48. proc main
  49. string DialString, PhoneNum, ComString, ComMsg, BBSName
  50. string  CnctFail1, CnctFail2, CnctFail3, CnctFail4, CnctFail5
  51. string char
  52. integer ComStringLength
  53. integer Attempts, MaxAttempts, DialOutTime, RingInterrupt
  54. integer i, j, n
  55. integer FirstCall
  56.     menudim()
  57.     checkchild()
  58.     profilerd MailRunIni "MailRun" "MailRunDir" MailRunDir
  59.     TaskList = makefullname(TempDir, "TASKLIST.TMP")
  60.     findfirst MailRun
  61.     MailRunTrunc = $FILENAME
  62.     maketasklist()
  63.     mailrunbox()
  64.     makequeue()
  65.     ;interface is turned on by makequeue
  66.     when dialog call parsedialog
  67.     profilerd MailRun "MailRun" "LogRun" LogRun
  68.     if LogRun
  69.         profilerd MailRun "MailRun" "AnsiInLog" AnsiInLog
  70.         if AnsiInLog
  71.             set capture mode append RAW
  72.         else
  73.             set capture mode append VISUAL
  74.         endif
  75.         capture ON
  76.     endif
  77.     profilerd MailRun "MailRun" "DialAttempts" MaxAttempts
  78.     fetch modem nocnct1 CnctFail1
  79.     fetch modem nocnct2 CnctFail2
  80.     fetch modem nocnct3 CnctFail3
  81.     fetch modem nocnct4 CnctFail4
  82.     fetch modem nocnct5 CnctFail5
  83.     Attempts = 1
  84.     FirstCall = 1
  85.     while Attempts <= MaxAttempts
  86.         itoa Attempts AttemptNum
  87.         updatedlg 64
  88.         ;Keep dialing until the maximum number of attempts has been made
  89.         ;reread MaxAttempts on each loop in case the user changes settings
  90.         profilerd MailRun "MailRun" "DialAttempts" MaxAttempts
  91.         n = 1
  92.         DialString = getdialstring(&n)
  93.         if n == 0
  94.             exitwhile
  95.         endif
  96.         while not NULLSTR DialString
  97.             ;Loop until all numbers have been called
  98.             strextract PhoneNum DialString "`t" 0
  99.             strextract char DialString "`t" 1
  100.             atoi char i
  101.             BBS = readbbs(i)
  102.             profilerd MailRun BBS "BBSName" BBSName
  103.             set aspect rxdata ON
  104.             rxflush
  105.             if FirstCall != 1
  106.                 ;Don't pause if this is the first call in the loop
  107.                 profilerd MailRun "MailRun" "DialPause" j
  108.                 profilerd MailRun "MailRun" "RingInterrupt" RingInterrupt 
  109.                 while j > 0
  110.                     statmsg "Last Message:  %s      Pausing  %d" ComMsg j
  111.                     pause 1
  112.                     j--
  113.                     ComStringLength = $RXCOUNT
  114.                     comgets ComString ComStringLength
  115.                     if RingInterrupt && findstring(ComString, "RING")
  116.                         capturescreen()
  117.                         capturestr \
  118.                             "`r`n`r`n**** Interrupted by Incoming Call ****`r`n`r`n"
  119.                         statmsg "Mailrun interrupted by incoming call"
  120.                         capture OFF
  121.                         exit
  122.                     endif
  123.                 endwhile
  124.             else
  125.                 FirstCall = 0
  126.             endif
  127.             ;Dial the BBS
  128.             strfmt ComString "ATDT%s`r" PhoneNum
  129.             strlen ComString ComStringLength
  130.             computs ComString ComStringLength
  131.             ;rxdata must be on in order to get characters from the modem
  132.             ComString = ""
  133.             ComMsg = ""
  134.             profilerd MailRun "MailRun" "DialTimeOut" DialOutTime
  135.             while (!$CARRIER) && (DialOutTime > 0)
  136.                 ;Loop until a connection is made, timeout is reached, or a
  137.                 ;negative connect message is received
  138.                 ComStringLength = $RXCOUNT
  139.                 comgets ComString ComStringLength
  140.                 if strfind ComString CnctFail1
  141.                     ComMsg = CnctFail1
  142.                     exitwhile
  143.                 elseif strfind ComString CnctFail2
  144.                     ComMsg = CnctFail2
  145.                     exitwhile
  146.                 elseif strfind ComString CnctFail3
  147.                     ComMsg = CnctFail3
  148.                     exitwhile
  149.                 elseif strfind ComString CnctFail4
  150.                     ComMsg = CnctFail4
  151.                     exitwhile
  152.                 elseif strfind ComString CnctFail5
  153.                     ComMsg = CnctFail5
  154.                     exitwhile
  155.                 endif
  156.                 rxflush
  157.                 statmsg "Dialing %s      %s     Waiting %d" \
  158.                     PhoneNum BBSName DialOutTime
  159.                 pause 1
  160.                 DialOutTime--
  161.             endwhile
  162.             set aspect rxdata OFF
  163.             if DialOutTime == 0
  164.                 ;If dial timed out...
  165.                 hangup
  166.                 ComMsg = "TIMEOUT"
  167.             endif
  168.             if $CARRIER
  169.                 ;if connected to a BBS...
  170.                 statmsg "Connected to %s" BBSName
  171.                 dobbs(i)
  172.                 makequeue()
  173.                 statmsg ""
  174.                 FirstCall = 1
  175.                 n--
  176.             endif
  177.             n++
  178.             DialString = getdialstring(&n)
  179.         endwhile
  180.         Attempts++
  181.     endwhile
  182.     capture OFF
  183.     statmsg ""
  184. endproc
  185.  
  186.  
  187. #comment
  188. *********************************************************************
  189. * DOBBS()
  190. * Called by main()
  191. * Calls readitem(), writeitem(), sendscript(), logoff(), fileexit()
  192. * maketasklist(), gettaskstring(), getcommandprompt(),
  193. * getmail(), sendmail(), dlfile(), ulfile(), sendcommand(),
  194. * Dispatches pending tasks for the BBS to which MailRun
  195. * is connected.
  196. *********************************************************************
  197. #endcomment
  198.  
  199. proc dobbs
  200. intparm i
  201. string Pending, TaskType, BBSName, BBSType
  202. integer FailCode
  203. integer j
  204.     ;Return to this point with a FailCode of 1 if carrier
  205.     ;is lost or the BBS times out
  206.     Failcode = 0
  207.     setjmp ErrorFail FailCode
  208.     if FailCode == 0
  209.         profilerd MailRun BBS "BBSType" BBSType
  210.         profilerd MailRun BBS "BBSName" BBSName
  211.         profilerd MailRun "MailRun" "IdleTimeout" IdleTimeout
  212.         ;Assume login to Conference 0
  213.         CurrentConf = "0"
  214.         Conf = "0"
  215.         strfmt TaskItem "%s`t`t`t%d`t%d" BBSName i 0
  216.         ;Highlight the current BBS in the task list
  217.         updatedlg 16
  218.  
  219.         ;The first item must be read before the first holding()
  220.         ;(which occurs in getcommandprompt()) in case an error occurs.
  221.         j = 1
  222.         Item = readitem(j)
  223.         getcommandprompt()
  224.         while not NULLSTR Item
  225.             ;Loop through each Item for this BBS
  226.             TaskItem = gettaskstring(i, j)
  227.             updatedlg 16
  228.             strextract Pending Item "," 0
  229.             if strcmpi Pending "1"
  230.                 ;If the item is pending, execute it
  231.                 strextract TaskType Item "," 2
  232.                 switch TaskType
  233.                     case "GetMail"
  234.                         statmsg "Getting Mail Packet"
  235.                         getmail()
  236.                     endcase
  237.                     case "SendMail"
  238.                         statmsg "Sending Reply Packet"
  239.                         sendmail()
  240.                     endcase
  241.                     case "GetFile"
  242.                         statmsg "Downloading File"
  243.                         dlfile()
  244.                     endcase
  245.                     case "SendFile"
  246.                         statmsg "Uploading File"
  247.                         ulfile()
  248.                     endcase
  249.                     case "SendCommand"
  250.                         statmsg "Sending Command"
  251.                         sendcommand()
  252.                     endcase
  253.                     case "SendScript"
  254.                         statmsg "Executing Script"
  255.                         sendscript()
  256.                     endcase
  257.                 endswitch
  258.                 ;Update the task list
  259.                 writeitem(j, Item)
  260.                 maketasklist()
  261.                 TaskItem = gettaskstring(i, j)
  262.                 ;Highlight the last completed item
  263.                 updatedlg 80
  264.             endif
  265.             j++
  266.             Item = readitem(j)
  267.         endwhile
  268.         getcommandprompt()
  269.     else
  270.         ;If timeout or loss of carrier
  271.         ;Change unfinished items to errors
  272.         while not NULLSTR Item
  273.             strextract Pending Item "," 0
  274.             if strcmpi Pending "1"
  275.                 strupdt Item "2" 0 1
  276.                 writeitem(j, Item)
  277.             endif
  278.             j++
  279.             Item = readitem(j)
  280.         endwhile
  281.         maketasklist()
  282.         j--
  283.         Item = readitem(j)
  284.         TaskItem = gettaskstring(i, j)
  285.         updatedlg 80
  286.     endif
  287.     statmsg "Logging off"
  288.     logoff()
  289.     if $CARRIER
  290.         ;If still connected after logoff...
  291.         errormsg "Unable to drop carrier; aborting..."
  292.         ;abort the mailrun
  293.         fileexit()
  294.     endif
  295. endproc
  296.  
  297.  
  298. #comment
  299. *********************************************************************
  300. * MAKEQUEUE()
  301. * Called by main(), parsedialog()
  302. * Calls openfile(), readbbs(), checkpending(),
  303. * interfaceon(), interfaceoff(), makefullname()
  304. * Creates a file of phone numbers for BBSs that have
  305. * pending items in the current mailrun.
  306. *********************************************************************
  307. #endcomment
  308.  
  309. proc makequeue
  310. string Pending, PhoneNum, Number_X, QueueList
  311. integer i, j
  312.     interfaceoff()
  313.     QueueList = makefullname(TempDir, "QUEUE.TMP")
  314.     openfile(QueueListFile, QueueList, _CREATE, _NORMAL)
  315.     i = 1
  316.     BBS = readbbs(i)
  317.     ;Loop through each BBS
  318.     while not NULLSTR BBS
  319.         pending = checkpending()
  320.         if strcmpi Pending "1"
  321.             ;If the BBS has pending items...
  322.             j = 1
  323.             strfmt Number_X "Number_%d" j
  324.             profilerd MailRun BBS Number_X PhoneNum
  325.             ;Loop through each phone number
  326.             while not NULLSTR PhoneNum
  327.                 fstrfmt QueueListFile "%s`t%d`r`n" PhoneNum i
  328.                 j++
  329.                 strfmt Number_X "Number_%d" j
  330.                 profilerd MailRun BBS Number_X PhoneNum
  331.             endwhile
  332.         endif
  333.         i++
  334.         BBS = readbbs(i)
  335.     endwhile
  336.     fclose QueueListFile
  337.     interfaceon()
  338. endproc
  339.  
  340.  
  341. #comment
  342. *********************************************************************
  343. * GETDIALSTRING()
  344. * Called by main()
  345. * Calls makefullname(), interfaceon(), interfaceoff(),
  346. * openfile()
  347. * Gets a DialString from the queue.  The string contains
  348. * a phone number and a bbs coordinate.
  349. *********************************************************************
  350. #endcomment
  351.  
  352. func getdialstring : string
  353. intparm n
  354. integer i
  355. string DialString, QueueList
  356.     interfaceoff()
  357.     DialString = ""
  358.     QueueList = makefullname(TempDir, "QUEUE.TMP")
  359.     openfile(QueueListFile, QueueList, _READWRITE, _TEXT)
  360.     i = 1
  361.     while i <= n
  362.         fgets QueueListFile DialString
  363.         if NULLSTR DialString
  364.             n = 0
  365.             exitwhile
  366.         endif
  367.         i++
  368.     endwhile
  369.     fclose QueueListFile
  370.     interfaceon()
  371.     return DialString
  372. endfunc
  373.  
  374.  
  375. #comment
  376. *********************************************************************
  377. * GETCOMMANDPROMPT()
  378. * Called by dobbs(), getconfprompt(), getotherprompt(),
  379. * ulfile(), dlfile(), sendcommand(), sendscript()
  380. * Calls holding(), checkcommandprompt()
  381. * Responds to prompts until the "Command" prompt is received.
  382. *********************************************************************
  383. #endcomment
  384.  
  385. proc getcommandprompt
  386.     when quiet 1 call checkcommandprompt
  387.     holding()
  388.     clearwhen quiet
  389. endproc
  390.  
  391.  
  392. #comment
  393. *********************************************************************
  394. * CHECKCOMMANDPROMPT()
  395. * Called by getcommandprompt()
  396. * Calls checkbaseset(), findstring(), endhold()
  397. * Checks the prompt and sends the appropriate response.
  398. *********************************************************************
  399. #endcomment
  400.  
  401. proc checkcommandprompt
  402. string NamePrompt, UserName, BBSType
  403. string PWordPrompt, PWord, FilePrompt
  404. string MailPrompt, CommandPrompt, MsgMenuPrompt
  405.     profilerd MailRun BBS "BBSType" BBSType
  406.     profilerd MailRun BBS "NamePrompt" NamePrompt
  407.     profilerd MailRun BBS "PWordPrompt" PWordPrompt
  408.     profilerd MailRun BBS "FilePrompt" FilePrompt
  409.     profilerd MailRun BBS "MailPrompt" MailPrompt
  410.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  411.     profilerd MailRun BBS "MsgMenuPrompt" MsgMenuPrompt
  412.     if !(checkbaseset())
  413.         if findstring(prompt, MailPrompt) || \
  414.             (findstring(BBSType, "WildCat") && \
  415.             findstring(prompt, MsgMenuPrompt))
  416.             transmit "q^M"
  417.         elseif findstring(BBSType, "WildCat") && \
  418.             findstring(prompt, "Join conference")
  419.             transmit Conf
  420.             transmit "^M"
  421.         elseif findstring(prompt, NamePrompt)
  422.             profilerd MailRun BBS "UserName" UserName
  423.             transmit UserName
  424.             transmit "^M"
  425.         elseif findstring(prompt, PWordPrompt)
  426.             profilerd MailRun BBS "PWord" PWord
  427.             transmit PWord
  428.             transmit "^M"
  429.         elseif findstring(prompt, "Escape") || findstring(prompt, " ESC ")
  430.             ;send escape character
  431.             computc 0x1B
  432.           if findstring(prompt, "twice") || findstring(prompt, "two")
  433.                 ;pause 50 milliseconds
  434.                 mspause 50
  435.                 computc 0x1B
  436.             endif
  437.         elseif findstring(prompt, CommandPrompt) || \
  438.             findstring(prompt, FilePrompt)
  439.             endhold()
  440.         endif
  441.     endif
  442. endproc
  443.  
  444.  
  445. #comment
  446. *********************************************************************
  447. * GETCONFPROMPT()
  448. * Called by ulfile(), dlfile()
  449. * Calls getcommandprompt(), findstring()
  450. * Changes conferences if necessary.
  451. *********************************************************************
  452. #endcomment
  453.  
  454. proc getconfprompt
  455. string BBSType
  456.     profilerd MailRun BBS "BBSType" BBSType
  457.     if not strcmpi CurrentConf Conf
  458.         ;If we have to change conferences...
  459.         if findstring(BBSType, "WildCat")
  460.             transmit "j^M"
  461.         elseif findstring(BBSType, "PCBoard")
  462.             transmit "j;"
  463.             transmit Conf
  464.             transmit "^M"
  465.         endif
  466.         getcommandprompt()
  467.         CurrentConf = Conf
  468.     endif
  469. endproc
  470.  
  471.  
  472. #comment
  473. *********************************************************************
  474. * CHECKMAILPROMPT()
  475. * Called by getmail(), sendmail()
  476. * Calls endhold(), findstring(), checkbaseset()
  477. * Opens the mail door and gets the mail prompt.
  478. *********************************************************************
  479. #endcomment
  480.  
  481. proc checkmailprompt
  482. string MailPrompt, CommandPrompt, MailDoor, FilePrompt
  483. string BBSType, MsgMenuPrompt
  484.     profilerd MailRun BBS "BBSType" BBSType
  485.     profilerd MailRun BBS "MsgMenuPrompt" MsgMenuPrompt
  486.     profilerd MailRun BBS "MailPrompt" MailPrompt
  487.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  488.     profilerd MailRun BBS "FilePrompt" FilePrompt
  489.     if !(checkbaseset())
  490.         if findstring(BBSType, "WildCat") && \
  491.             (findstring(prompt, CommandPrompt) || findstring(prompt, FilePrompt))
  492.             transmit "M^M"
  493.         elseif findstring(prompt, MailPrompt)
  494.             endhold()
  495.         elseif (findstring(prompt, CommandPrompt) && \
  496.             (findstring(BBSType, "PCBoard") || findstring(BBSType, "RBBS"))) || \
  497.             (findstring(BBSType, "WildCat") && findstring(prompt, MsgMenuPrompt))
  498.             profilerd MailRun BBS "MailDoor" MailDoor
  499.             transmit MailDoor
  500.             transmit "^M"
  501.         endif
  502.     endif
  503. endproc
  504.  
  505.  
  506. #comment
  507. *********************************************************************
  508. * CHECKDESCPROMPT()
  509. * Called by ulfile(), dlfile()
  510. * Calls findstring(), endhold(), checkbaseset()
  511. * Checks for presense of the upload description prompt.
  512. * Sets promptstatus to 0 if the file already on the board.
  513. *********************************************************************
  514. #endcomment
  515.  
  516. proc checkdescprompt
  517. string ULDescPrompt, DLUnavPrompt, CommandPrompt, FilePrompt, BBSType
  518.     profilerd MailRun BBS "BBSType" BBSType
  519.     profilerd MailRun BBS "ULDescPrompt" ULDescPrompt
  520.     profilerd MailRun BBS "DLUnavPrompt" DLUnavPrompt
  521.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  522.     profilerd MailRun BBS "FilePrompt" FilePrompt
  523.     if !(checkbaseset())
  524.         if findstring(prompt, "file # 2") || findstring(prompt, "file #2") || \
  525.             findstring(prompt, "Keywords? [")
  526.             transmit "^M"
  527.         elseif (findstring(BBSType, "WildCat") && \
  528.             (findstring(prompt, "password protect") || \
  529.             findstring(prompt, "detailed") || \
  530.             findstring(prompt, "last download"))) || \
  531.             (findstring(BBSType, "RBBS") && \
  532.             findstring(prompt, "Extended description"))
  533.             transmit "n^M"
  534.         elseif findstring(prompt, "after upload")
  535.             transmit "c^M"
  536.         elseif findstring(BBSType, "RBBS") && findstring(prompt, "To A)ll")
  537.             transmit "a^M"
  538.             foundstatus = 1
  539.             endhold()
  540.         elseif findstring(prompt, ULDescPrompt)
  541.             foundstatus = 1
  542.             endhold()
  543.         elseif findstring(prompt, DLUnavPrompt) || \
  544.             findstring(prompt, "file # 1") || findstring(prompt, "file #1") || \
  545.             findstring(prompt, CommandPrompt) || findstring(prompt, FilePrompt)
  546.             if findstring(BBSType, "Auntie") && !(findstring(prompt, FilePrompt))
  547.                 transmit "q^M"
  548.             endif
  549.             foundstatus = 0
  550.             endhold()
  551.         endif
  552.     endif
  553. endproc
  554.  
  555.  
  556. #comment
  557. *********************************************************************
  558. * GOTULDLPROMPT()
  559. * Called by ulfile()
  560. * Releases the hold when the upload prompt is received.
  561. *********************************************************************
  562. #endcomment
  563.  
  564. proc gotuldlprompt
  565.     foundstatus = 1
  566.     endhold()
  567. endproc
  568.  
  569.  
  570. #comment
  571. *********************************************************************
  572. * GETOTHERPROMPT()
  573. * Called by sendmail(), getmail(), ulfile(), dlfile(),
  574. * sendcommand(), sendscript()
  575. * Calls findstring(), getcommandprompt()
  576. * For BBSs with a separate File prompt, moves to or from
  577. * the prompt.
  578. *********************************************************************
  579. #endcomment
  580.  
  581. proc getotherprompt
  582. intparm gotoplace
  583. string FilePrompt, BBSType
  584.     profilerd MailRun BBS "BBSType" BBSType
  585.     profilerd MailRun BBS "FilePrompt" FilePrompt
  586.     if !(findstring(prompt, FilePrompt)) && (gotoplace == GOTOFILE)
  587.         transmit "f^M"
  588.     elseif findstring(prompt, FilePrompt) && (gotoplace == GOTOMAIN)
  589.         transmit "q"
  590.         if findstring(BBSType, "RBBS")
  591.             transmit ";m"
  592.         endif
  593.         transmit "^M"
  594.     endif
  595.     getcommandprompt()
  596. endproc
  597.  
  598.  
  599. #comment
  600. *********************************************************************
  601. * CHECKBASESET()
  602. * Called by checkcommandprompt(), checkmailprompt(),
  603. * checkdescprompt()
  604. * Calls findstring()
  605. * Checks the base set of prompts.  Returns 1 if a prompt
  606. * was found; otherwise returns 0.
  607. *********************************************************************
  608. #endcomment
  609.  
  610. func checkbaseset : integer
  611. string LangPrompt, LangNumber, GraphicsPrompt, ScanPrompt
  612. string MorePrompt, ViewPrompt, CallingFrom, UserResp1, UserResp2
  613. string ContinuePrompt, UserPrompt1, UserPrompt2, BBSType
  614.     profilerd MailRun BBS "BBSType" BBSType
  615.     profilerd MailRun BBS "CallingFrom" CallingFrom
  616.     profilerd MailRun BBS "UserPrompt1" UserPrompt1
  617.     profilerd MailRun BBS "UserPrompt2" UserPrompt2
  618.     profilerd MailRun BBS "UserResp1" UserResp1
  619.     profilerd MailRun BBS "UserResp2" UserResp2
  620.     profilerd MailRun BBS "ContinuePrompt" ContinuePrompt
  621.     profilerd MailRun BBS "ScanPrompt" ScanPrompt
  622.     profilerd MailRun BBS "MorePrompt" MorePrompt
  623.     profilerd MailRun BBS "ViewPrompt" ViewPrompt
  624.     profilerd MailRun BBS "LangPrompt" LangPrompt
  625.     profilerd MailRun BBS "GraphicsPrompt" GraphicsPrompt
  626.     if findstring(prompt, UserPrompt1)
  627.         transmit UserResp1
  628.         transmit "^M"
  629.     elseif findstring(prompt, UserPrompt2)
  630.         transmit UserResp2
  631.         transmit "^M"
  632.     elseif findstring(prompt, ScanPrompt) || \
  633.         (findstring(prompt, MorePrompt) && !(findstring(BBSType, "WildCat")))
  634.         transmit "n^M"
  635.     elseif findstring(prompt, MorePrompt) && \
  636.         findstring(BBSType, "WildCat")
  637.         transmit "s^M"
  638.     elseif (findstring(prompt, ContinuePrompt) && \
  639.         findstring(BBSType, "PCBoard")) || \
  640.         findstring(prompt, CallingFrom)
  641.         transmit "y^M"
  642.     elseif findstring(prompt, ContinuePrompt) && \
  643.         !(findstring(BBSType, "PCBoard"))
  644.         transmit "^M"
  645.     elseif findstring(prompt, ViewPrompt)
  646.         if findstring(BBSType, "PCBoard") || findstring(BBSType, "WildCat")
  647.             transmit "n"
  648.         elseif findstring(BBSType, "RBBS")
  649.             transmit "q"
  650.         endif
  651.         transmit "^M"
  652.     elseif findstring(prompt, LangPrompt)
  653.         profilerd MailRun BBS "LangNumber" LangNumber
  654.         transmit LangNumber
  655.         transmit "^M"
  656.     elseif findstring(prompt, GraphicsPrompt)
  657.         profilerd MailRun BBS "GraphicsOn" GraphicsOn
  658.         if GraphicsOn == 0
  659.             transmit "n^M"
  660.         else
  661.             transmit "y^M"
  662.         endif
  663.     else
  664.         return 0
  665.     endif
  666.     return 1
  667. endfunc
  668.  
  669.  
  670. #comment
  671. *********************************************************************
  672. * HOLDING()
  673. * Called by getcommandprompt(), sendmail(), getmail(),
  674. * ulfile(), dlfile(), sendcommand()
  675. *
  676. * Calls capturescreen()
  677. * Jumps to ErrorFail in dobbs()
  678. * Stalls script while waiting for the result of a when
  679. * command.  Sends script to next BBS if there is a
  680. * timeout, or if carrier is lost.
  681. *********************************************************************
  682. #endcomment
  683.  
  684. proc holding
  685. string LastPrompt
  686.     IdleTimer = 1
  687.     holdstatus = 1
  688.     prompt = ""
  689.     xferstatus = $FILEXFER
  690.     while (IdleTimer < IdleTimeout) && (holdstatus == 1) && \
  691.         (xferstatus == 0) && $CARRIER
  692.         pause 1
  693.         termgets $ROW 0 prompt 79
  694.         if not strcmp prompt LastPrompt
  695.             ;if anything has been received, reset the timer
  696.             IdleTimer = 1
  697.         endif
  698.         LastPrompt = prompt
  699.         if !(IdleTimer % 15)
  700.             ;Send a carriage return every 15 seconds
  701.             transmit "^M"
  702.         endif
  703.         IdleTimer++
  704.         xferstatus = $FILEXFER
  705.     endwhile
  706.     if (IdleTimer == IdleTimeout) || ($CARRIER == 0)
  707.         ;If there has been a timeout, lost carrier or user escape...
  708.         clearwhen quiet
  709.         ;set FailCode and get out
  710.         capturescreen()
  711.         if IdleTimer == IdleTimeout
  712.             capturestr "`r`n`r`n*** Timed out waiting for prompt ***`r`n`r`n"
  713.         else
  714.             capturestr "`r`n`r`n*********** Lost carrier ***********`r`n`r`n"
  715.         endif
  716.         longjmp ErrorFail 1
  717.     endif
  718. endproc
  719.  
  720.  
  721. #comment
  722. *********************************************************************
  723. * ENDHOLD()
  724. * Releases a hold placed by holding()
  725. *********************************************************************
  726. #endcomment
  727.  
  728. proc endhold
  729.     holdstatus = 0
  730. endproc
  731.  
  732.  
  733. #comment
  734. *********************************************************************
  735. * WAITXFER()
  736. * Called by sendmail(), getmail(), ulfile(), dlfile()
  737. * Stalls script until a file transfer has been completed.
  738. *********************************************************************
  739. #endcomment
  740.  
  741. proc waitxfer
  742.     xferstatus = $FILEXFER
  743.     while xferstatus == 1
  744.         xferstatus = $FILEXFER
  745.     endwhile
  746. endproc
  747.  
  748.  
  749. #comment
  750. *********************************************************************
  751. * SENDMAIL()
  752. * Called by dobbs()
  753. * Calls checkmailprompt(), holding(), waitxfer(),
  754. * findstring(), makefullname(), getotherprompt(),
  755. * capturescreen()
  756. * Uploads a *.REP packet for the current BBS.
  757. *********************************************************************
  758. #endcomment
  759.  
  760. proc sendmail
  761. string MailULPrompt, MailXferProt, BBSType
  762. string ReplyFile, ReplyDir
  763. string Pending, temp
  764. integer j
  765.     profilerd MailRun BBS "BBSType" BBSType
  766.     profilerd MailRun "MailRun" "ReplyDir" ReplyDir
  767.     ReplyFile = makefullname(ReplyDir, BBS)
  768.     strcat ReplyFile ".REP"
  769.     if isfile ReplyFile
  770.         ;If there is a REP packet waiting...
  771.         if findstring(BBSType, "Auntie") || findstring(BBSType, "RBBS")
  772.             getotherprompt(GOTOMAIN)
  773.         endif
  774.         if findstring(BBSType, "Auntie")
  775.             transmit "QMU^M"
  776.         else
  777.             when quiet 1 call checkmailprompt
  778.             holding()
  779.             clearwhen quiet
  780.             transmit "u^M"
  781.         endif
  782.         profilerd MailRun BBS "MailULPrompt" MailULPrompt
  783.         when target 0 MailULPrompt call endhold
  784.         holding()
  785.         clearwhen target 0
  786.         set upldpath ReplyDir
  787.         profilerd MailRun BBS "MailXferProt" MailXferProt
  788.         sendfile MailXferProt ReplyFile
  789.         ;Hold until the transfer starts
  790.         holding()
  791.         ;Hold until the transfer finishes
  792.         waitxfer()
  793.         if xferstatus == 2
  794.             ;If upload was successful...
  795.             ;Rename the .REP packet as *.OLD
  796.             temp = ReplyFile
  797.             strlen temp j
  798.             j -= 3
  799.             strupdt temp "OLD" j 3
  800.             delfile temp
  801.             rename ReplyFile temp
  802.             ;Mark the Item as completed
  803.             Pending = "0"
  804.         else
  805.             ;Otherwise, mark it as an error
  806.             Pending = "2"
  807.             capturescreen()
  808.             capturestr "`r`n`r`n******* Error in File Transfer *******`r`n`r`n"
  809.         endif
  810.     else
  811.         Pending = "0"
  812.     endif
  813.     ;Update the *.MRN file
  814.     strupdt Item Pending 0 1
  815. endproc
  816.  
  817.  
  818. #comment
  819. *********************************************************************
  820. * GETMAIL()
  821. * Called by dobbs()
  822. * Calls checkmailprompt(), holding(), waitxfer, cleardir(),
  823. * renameqwk(), checkmail(), findstring(), makefullname(),
  824. * getotherprompt(), capturescreen()
  825. * Downloads a *.QWK packet for the current BBS.
  826. *********************************************************************
  827. #endcomment
  828.  
  829. proc getmail
  830. string MailFile, MailDLDir, MailDLPrompt, MailXferProt, CommandPrompt
  831. string Pending, temp, BBSType
  832.     profilerd MailRun BBS "BBSType" BBSType
  833.     foundstatus = 1
  834.     if findstring(BBSType, "Auntie") || findstring(BBSType, "RBBS") 
  835.         getotherprompt(GOTOMAIN)
  836.     endif
  837.     if findstring(BBSType, "Auntie")
  838.         transmit "QMD^M"
  839.     else
  840.         when quiet 1 call checkmailprompt
  841.         holding()
  842.         clearwhen quiet
  843.         transmit "d^M"
  844.         ;Wait for a prompt indicated presense of mail
  845.         when quiet 1 call checkmail
  846.         holding()
  847.         clearwhen quiet
  848.         if foundstatus == 0
  849.             Pending = "0"
  850.             strupdt Item Pending 0 1
  851.             return
  852.         endif
  853.         ;If there is mail...
  854.         transmit "y^M"
  855.     endif
  856.     ;Wait until asked to start the download
  857.     profilerd MailRun BBS "MailDLPrompt" MailDLPrompt
  858.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  859.     when target 0 MailDLPrompt call endhold
  860.     when target 1 CommandPrompt call killmaildl
  861.     holding()
  862.     clearwhen target 0
  863.     clearwhen target 1
  864.     ;If the command prompt has put in an appearance, abort the d/l
  865.     if foundstatus == 0
  866.         Pending = "0"
  867.         strupdt Item Pending 0 1
  868.         return
  869.     endif
  870.     ;Download to the mail download directory
  871.     MailDLDir = makefullname(MailRunDir, "MAILDL")
  872.     mkdir MailDLDir
  873.     cleardir(MailDLDir)
  874.     set dnldpath MailDLDir
  875.     strfmt temp "%s.QWK" BBS
  876.     profilerd MailRun BBS "MailXferProt" MailXferProt
  877.     getfile MailXferProt temp
  878.     ;Hold until the transfer starts
  879.     holding()
  880.     ;Hold until the transfer finishes
  881.     waitxfer()
  882.     if xferstatus == 2
  883.         ;If the download was successful...
  884.         ;Make sure the mail file has the ".QWK" extension.
  885.             ;This complicated workaround is the only way I could
  886.         ;figure out how to get the filename of a file that has
  887.         ;just been downloaded.
  888.         temp = makefullname(MailDLDir, "*.*")
  889.         findfirst temp
  890.         temp = makefullname(MailDLDir, $FILENAME)
  891.         MailFile = makefullname(MailDLDir, BBS)
  892.         strcat MailFile ".QWK"
  893.         rename temp MailFile
  894.         ;Renumber the QWK packets
  895.         renameqwk(MailFile)
  896.         ;and mark it as completed
  897.         Pending = "0"
  898.     else
  899.         ;Otherwise, mark the item as an error
  900.         Pending = "2"
  901.         capturescreen()
  902.         capturestr "`r`n`r`n***** Error in File Transfer *****`r`n`r`n"
  903.     endif
  904.     ;Delete the mail download directory
  905.     cleardir(MailDLDir)
  906.     chdir MailRunDir
  907.     rmdir MailDLDir
  908.     strupdt Item Pending 0 1
  909. endproc
  910.  
  911.  
  912. #comment
  913. *********************************************************************
  914. * CHECKMAIL()
  915. * Called by getmail()
  916. * Calls findstring(), endhold()
  917. * Checks prompt for presense of a mail packet.
  918. *********************************************************************
  919. #endcomment
  920.  
  921. proc checkmail
  922. string ReceiveQWKPrompt, MailPrompt
  923.     profilerd MailRun BBS "ReceiveQWKPrompt" ReceiveQWKPrompt
  924.     profilerd MailRun BBS "MailPrompt" MailPrompt
  925.     if findstring(prompt, MailPrompt)
  926.         foundstatus = 0
  927.         endhold()
  928.     elseif findstring(prompt, ReceiveQWKPrompt)
  929.         endhold()
  930.     endif
  931. endproc
  932.  
  933.  
  934. #comment
  935. *********************************************************************
  936. * KILLMAILDL()
  937. * Called by getmail()
  938. * If there is no mail packet, kills attempt to d/l.
  939. *********************************************************************
  940. #endcomment
  941.  
  942. proc killmaildl
  943.     foundstatus = 0
  944.     endhold()
  945. endproc
  946.  
  947.  
  948. #comment
  949. *********************************************************************
  950. * RENAMEQWK()
  951. * Called by getmail()
  952. * Calls makefullname()
  953. * Renames QWK packets after a successful mail download.
  954. *********************************************************************
  955. #endcomment
  956.  
  957. proc renameqwk
  958. strparm MailFile
  959. string OldMail1, OldMail2, MailDir
  960. string char
  961. integer i, j
  962.     profilerd MailRun "MailRun" "MailDir" MailDir
  963.     OldMail2 = makefullname(MailDir, BBS)
  964.     profilerd MailRun "MailRun" "SavePackets" i
  965.     ;max of 10 packets
  966.     if i > 10
  967.         i = 10
  968.     endif
  969.     i -= 1
  970.     if i > 0
  971.         strfmt OldMail2 "%s.QW%d" OldMail2 i
  972.     elseif i == 0
  973.         strfmt OldMail2 "%s.QW0" OldMail2
  974.     else
  975.         strfmt OldMail2 "%s.QWK" OldMail2
  976.     endif
  977.     ;Delete oldest file
  978.     delfile OldMail2
  979.     OldMail1 = OldMail2
  980.     strlen OldMail1 j
  981.     j -= 1
  982.     while i > 0
  983.         i--
  984.         itoa i char
  985.         strupdt OldMail1 char j 1
  986.         ;Rename the second oldest as the oldest
  987.         rename OldMail1 OldMail2
  988.         ;Rotate filenames
  989.         OldMail2 = OldMail1
  990.     endwhile
  991.     if i == 0
  992.         ;if the oldest is QW0...
  993.         strupdt OldMail1 "K" j 1
  994.         rename OldMail1 OldMail2
  995.         OldMail2 = OldMail1
  996.     endif
  997.     delfile OldMail2
  998.     copyfile MailFile OldMail1
  999.     delfile MailFile
  1000. endproc
  1001.  
  1002.  
  1003. #comment
  1004. *********************************************************************
  1005. * ULFILE()
  1006. * Called by dobbs()
  1007. * Calls getconfprompt(), getcommandprompt(), getotherprompt(),
  1008. * holding(), waitxfer(), checkdescprompt(), findstring(),
  1009. * checkverifyprompt(), gotuldlprompt(), senddesc(),
  1010. * capturescreen()
  1011. * Uploads a file to the current BBS.
  1012. *********************************************************************
  1013. #endcomment
  1014.  
  1015. proc ulfile
  1016. string Pending, ULPrompt, ULDescPrompt, UploadDir, XferProt
  1017. string FileName, BBSType
  1018.     profilerd MailRun BBS "BBSType" BBSType
  1019.     Pending = "2"
  1020.     strextract FileName Item "," 3
  1021.     strextract Conf item "," 4
  1022.     ;Change conferences if necessary
  1023.     getcommandprompt()
  1024.     if findstring(BBSType, "PCBoard") || findstring(BBSType, "WildCat")
  1025.         getconfprompt()
  1026.     endif
  1027.     if !(findstring(BBSType, "PCBoard"))
  1028.         getotherprompt(GOTOFILE)
  1029.     endif
  1030.     if findstring(BBSType, "WildCat")
  1031.         transmit "u^M"
  1032.         when quiet 1 call checkdescprompt
  1033.         holding()
  1034.         clearwhen quiet
  1035.     else
  1036.         transmit "u;"
  1037.     endif
  1038.     transmit FileName
  1039.     if findstring(BBSType, "Auntie")
  1040.         transmit ";n"
  1041.     endif
  1042.     transmit "^M"
  1043.     ;Check whether file is already on the board
  1044.     when quiet 1 call checkdescprompt
  1045.     holding()
  1046.     clearwhen quiet
  1047.     if foundstatus == 1
  1048.         if !(findstring(BBSType, "RBBS"))
  1049.             senddesc(FileName)
  1050.         endif
  1051.         if findstring(BBSType, "Auntie")
  1052.             when quiet 1 call checkverifyprompt
  1053.             holding()
  1054.             clearwhen quiet
  1055.         endif
  1056.         profilerd MailRun BBS "ULPrompt" ULPrompt
  1057.         when target 0 ULPrompt call gotuldlprompt
  1058.         when quiet 1 call checkdescprompt
  1059.         holding()
  1060.         clearwhen quiet
  1061.         clearwhen target 0
  1062.         xferstatus = 1
  1063.         profilerd MailRun "MailRun" "UploadDir" UploadDir
  1064.         set upldpath UploadDir
  1065.         profilerd MailRun BBS "XferProt" XferProt
  1066.         sendfile XferProt FileName
  1067.         ;Wait until the transfer starts
  1068.         holding()
  1069.         ;Wait until the transfer finishes
  1070.         waitxfer()
  1071.         if xferstatus == 2
  1072.             ;If the download was successful...
  1073.             if findstring(BBSType, "RBBS")
  1074.                 when quiet 1 call checkverifyprompt
  1075.                 holding()
  1076.                 clearwhen quiet
  1077.                 profilerd MailRun BBS "ULDescPrompt" ULDescPrompt
  1078.                 when target 0 ULDescPrompt call endhold
  1079.                 when quiet 1 call checkdescprompt
  1080.                 holding()
  1081.                 clearwhen quiet
  1082.                 clearwhen target 0
  1083.                 if foundstatus == 1
  1084.                     senddesc(FileName)
  1085.                     when quiet 1 call checkdescprompt
  1086.                     holding()
  1087.                     clearwhen quiet
  1088.                 endif
  1089.             endif
  1090.             ;Mark as completed
  1091.             Pending = "0"
  1092.         else
  1093.             ;Otherwise, mark as an error
  1094.             capturescreen()
  1095.             capturestr "`r`n`r`n***** Error in File Transfer *****`r`n`r`n"
  1096.         endif
  1097.     else
  1098.         ;If the file was already on the board
  1099.         ;Send a carriage return to get the prompt back
  1100.         transmit "^M"
  1101.         if findstring(BBSType, "WildCat")
  1102.             pause 1
  1103.             transmit "A^M"
  1104.         endif
  1105.     endif
  1106.     strupdt Item Pending 0 1
  1107. endproc
  1108.  
  1109.  
  1110. #comment
  1111. *********************************************************************
  1112. * CHECKVERIFYPROMPT()
  1113. * Called by ulfile()
  1114. * Calls findstring(), endhold()
  1115. * Checks for prompt to send the category or file area to
  1116. * which a file should be uploaded.
  1117. *********************************************************************
  1118. #endcomment
  1119.  
  1120. proc checkverifyprompt
  1121. string BBSType
  1122.     profilerd MailRun BBS "BBSType" BBSType
  1123.     if findstring(BBSType, "Auntie") && findstring(prompt, "editor function")
  1124.         transmit "s^M"
  1125.     elseif findstring(prompt, "category")
  1126.         transmit Conf
  1127.         if findstring(BBSType, "Auntie")
  1128.             transmit ";y;n^M"
  1129.         endif
  1130.         endhold()
  1131.     endif
  1132. endproc
  1133.  
  1134.  
  1135. #comment
  1136. *********************************************************************
  1137. * SENDDESC()
  1138. * Called by ulfile()
  1139. * Calls checkfile(), makefullname(), openfile(), interfaceon(),
  1140. * interfaceoff(), findstring()
  1141. * Sends the file description of a file to be uploaded;
  1142. * otherwise sends "Description not available".
  1143. *********************************************************************
  1144. #endcomment
  1145.  
  1146. proc senddesc
  1147. strparm FileName
  1148. string UDXString, UDXFile, MRunUDX, MRunUBF, BBSType
  1149. string DB, DL
  1150. integer char
  1151. long DescBegin, DescLength
  1152. long counter
  1153.     profilerd MailRun BBS "BBSType" BBSType
  1154.     MRunUDX = makefullname(MailRunDir, "MAILRUN.UDX")
  1155.     MRunUBF = makefullname(MailRunDir, "MAILRUN.UBF")
  1156.     ;If the file is not on the board, send a description
  1157.     if checkfile(MRunUDX) && checkfile(MRunUBF)
  1158.         interfaceoff()
  1159.         openfile(MRunUBFFile, MRunUBF, _READWRITE, _NORMAL)
  1160.         openfile(MRunUDXFile, MRunUDX, _READWRITE, _TEXT)
  1161.         fgets MRunUDXFile UDXString
  1162.         strextract UDXFile UDXString "`t" 0
  1163.         while not strcmpi UDXFile FileName
  1164.             fgets MRunUDXFile UDXString
  1165.             strextract UDXFile UDXString "`t" 0
  1166.         endwhile
  1167.         strextract DB UDXString "`t" 4
  1168.         strextract DL UDXString "`t" 5
  1169.         atol DB DescBegin
  1170.         atol DL DescLength
  1171.         if findstring(BBSType, "WildCat")
  1172.             if DescLength > 60
  1173.                 DescLength = 60
  1174.             endif
  1175.         endif
  1176.         if findstring(BBSType, "RBBS")
  1177.             if DescLength > 45
  1178.                 DescLength = 45
  1179.             endif
  1180.         endif
  1181.         fseek MRunUBFFile DescBegin 0
  1182.         for counter = 1 upto DescLength
  1183.             fgetc MRunUBFFile char
  1184.             computc char
  1185.         endfor
  1186.         fclose MRunUBFFile
  1187.         fclose MRunUDXFile
  1188.         interfaceon()
  1189.     else
  1190.         transmit "Description not available"
  1191.     endif
  1192.     transmit "^M"
  1193.     if findstring(BBSType, "PCBoard") || findstring(BBSType, "Auntie")
  1194.         transmit "^M"
  1195.     endif
  1196. endproc
  1197.  
  1198.  
  1199. #comment
  1200. *********************************************************************
  1201. * DLFILE()
  1202. * Called by dobbs()
  1203. * Calls getconfprompt(), getcommandprompt(), getotherprompt(),
  1204. * holding(), waitxfer(), putdesc(), findstring(),
  1205. * checkdescprompt(), gotuldlprompt(), capturescreen()
  1206. * Downloads a file from the current BBS.
  1207. *********************************************************************
  1208. #endcomment
  1209.  
  1210. proc dlfile
  1211. string Pending, DLPrompt, DownloadDir, XferProt, FileName, BBSType
  1212.     profilerd MailRun BBS "BBSType" BBSType
  1213.     strextract FileName Item "," 3
  1214.     strextract Conf Item "," 4
  1215.     ;Change conferences if necessary
  1216.     getcommandprompt()
  1217.     if !(findstring(BBSType, "Auntie"))
  1218.         getconfprompt()
  1219.     endif
  1220.     if !(findstring(BBSType, "PCBoard"))
  1221.         getotherprompt(GOTOFILE)
  1222.     endif
  1223.     if findstring(BBSType, "WildCat")
  1224.         transmit "d^M"
  1225.         when quiet 1 call checkdescprompt
  1226.         holding()
  1227.         clearwhen quiet
  1228.     else
  1229.         transmit "d;"
  1230.     endif
  1231.     transmit FileName
  1232.     transmit "^M"
  1233.     ;Check whether file is available for d/l
  1234.     profilerd MailRun BBS "DLPrompt" DLPrompt
  1235.     when target 0 DLPrompt call gotuldlprompt
  1236.     when quiet 1 call checkdescprompt
  1237.     holding()
  1238.     clearwhen quiet
  1239.     clearwhen target 0
  1240.     if foundstatus == 1
  1241.         ;If it is available...
  1242.         profilerd MailRun "MailRun" "DownloadDir" DownloadDir
  1243.         set dnldpath DownloadDir
  1244.         profilerd MailRun BBS "XferProt" XferProt
  1245.         getfile XferProt FileName
  1246.         ;Wait until the transfer starts
  1247.         holding()
  1248.         ;Wait until the transfer finishes
  1249.         waitxfer()
  1250.         if xferstatus == 2
  1251.             ;If the download was successful...
  1252.             putdesc(FileName)
  1253.             ;Mark as completed
  1254.             Pending = "0"
  1255.         else
  1256.             ;Otherwise, mark as an error
  1257.             Pending = "2"
  1258.             capturescreen()
  1259.             capturestr "`r`n`r`n*** Error in File Transfer ***`r`n`r`n"
  1260.         endif
  1261.     else
  1262.         ;If file was unavailable, mark as error.
  1263.         Pending = "2"
  1264.         ;Send a return to get the prompt back.
  1265.         transmit "^M"
  1266.     endif
  1267.     strupdt Item Pending 0 1
  1268. endproc
  1269.  
  1270.  
  1271. #comment
  1272. *********************************************************************
  1273. * PUTDESC()
  1274. * Called by dlfile()
  1275. * Calls openfile(), checkfile(), interfaceoff(), interfaceon(),
  1276. * makefullname()
  1277. * Searches the BBSs .IDX file for a file description and
  1278. * copies the description from the .DBF file to the uplaod
  1279. * files database.  If no description is found, a line
  1280. * including the file name, size and date is put in the
  1281. * upload files index.
  1282. *********************************************************************
  1283. #endcomment
  1284.  
  1285. proc putdesc
  1286. strparm FileName
  1287. string DB, DL, idxString, MRunUDX, MRunUBF, BBSidx, BBSdbf
  1288. string idxFile, idxDesc, FileDate, FullFileName, DownloadDir
  1289. integer inidx, char
  1290. long DescBegin, DescLength, counter, FileSize
  1291.     interfaceoff()
  1292.     ;Determine whether the BBS index and database files exist
  1293.     BBSidx = makefullname(MailRunDir, BBS)
  1294.     strfmt BBSdbf "%s.DBF" BBSidx
  1295.     strcat BBSidx ".IDX"
  1296.     inidx = 0
  1297.     if checkfile(BBSidx) && checkfile(BBSdbf)
  1298.         ;If both files exist...
  1299.         openfile(BBSidxFile, BBSidx, _READWRITE, _TEXT)
  1300.         fgets BBSidxFile idxString
  1301.         while not feof BBSidxFile
  1302.             ;Loop through the index file and stop if the file is found
  1303.             strextract idxFile idxString "`t" 0
  1304.             if strcmpi FileName idxFile
  1305.                 inidx = 1
  1306.                 exitwhile
  1307.             endif
  1308.             fgets BBSidxFile idxString
  1309.         endwhile
  1310.         fclose BBSidxFile
  1311.     endif
  1312.     strlwr FileName
  1313.     ;Get the file size and date
  1314.     profilerd MailRun "MailRun" "DownloadDir" DownloadDir
  1315.     FullFileName = makefullname(DownloadDir, FileName)
  1316.     getfsize FullFileName FileSize
  1317.     getfdate FullFileName FileDate
  1318.     ;Determine whether the upload index and database files exist
  1319.     MRunUDX = makefullname(MailRunDir, "MAILRUN.UDX")
  1320.     MRunUBF = makefullname(MailRunDir, "MAILRUN.UBF")
  1321.     if checkfile(MRunUBF) && checkfile(MRunUDX)
  1322.         ;If both files exist, open them
  1323.         openfile(MRunUBFFile, MRunUBF, _READWRITE, _NORMAL)
  1324.         openfile(MRunUDXFile, MRunUDX, _READWRITE, _NORMAL)
  1325.     else
  1326.         ;Otherwise, create them
  1327.         openfile(MRunUBFFile, MRunUBF, _CREATE, _NORMAL)
  1328.         openfile(MRunUDXFile, MRunUDX, _CREATE, _NORMAL)
  1329.     endif
  1330.     fseek MRunUDXFile 0 2
  1331.     if inidx == 1
  1332.         ;If the file was found in the BBS index...
  1333.         strextract idxDesc idxString "`t" 3
  1334.         ;Get the descriptions starting point and length...
  1335.         strextract DB idxString "`t" 4
  1336.         strextract DL idxString "`t" 5
  1337.         atol DB DescBegin
  1338.         atol DL DescLength
  1339.         openfile(BBSdbfFile, BBSdbf, _READWRITE, _NORMAL)
  1340.         fseek BBSdbfFile DescBegin 0
  1341.         fseek MRunUBFFile 0 2
  1342.         ftell MRunUBFFile DescBegin
  1343.         ;And copy each character of the description to the upload database
  1344.         for counter = 1 upto DescLength
  1345.             fgetc BBSdbfFile char
  1346.             fputc MRunUBFFile char
  1347.         endfor
  1348.         fclose BBSdbfFile
  1349.         ;Format the upload index entry
  1350.         fstrfmt MRunUDXFile "%s`t%ld`t%s`t%s`t%ld`t%ld`r`n" \
  1351.             FileName FileSize FileDate idxDesc DescBegin DescLength
  1352.     else
  1353.         ;If there was no entry in the BBS index...
  1354.         ;Format the upload index entry
  1355.         fstrfmt MRunUDXFile "%s`t%ld`t%s`t`t0`t0`r`n" FileName FileSize FileDate
  1356.     endif
  1357.     fclose MRunUBFFile
  1358.     fclose MRunUDXFile
  1359.     interfaceon()
  1360. endproc
  1361.  
  1362.  
  1363. #comment
  1364. *********************************************************************
  1365. * SENDCOMMAND()
  1366. * Called by dobbs()
  1367. * Calls getcommandprompt(), getotherprompt(), holding(), 
  1368. * findstring()
  1369. * Sends commands to the current BBS.  A command item may
  1370. * contain multiple command lines separated by a vertical
  1371. * bar.  The script will send these one at a time, waiting
  1372. * until the terminal has been quiet for 15 seconds before
  1373. * sending the next one.  The command must return the user
  1374. * to the Main Command Prompt, or be the last item for the
  1375. * BBS.
  1376. *********************************************************************
  1377. #endcomment
  1378.  
  1379. proc sendcommand
  1380. string CommandLine, Command, BBSType
  1381. integer j
  1382.     getcommandprompt()
  1383.     profilerd MailRun BBS "BBSType" BBSType
  1384.     if !(findstring(BBSType, "PCBoard"))
  1385.         getotherprompt(GOTOMAIN)
  1386.     endif
  1387.     strextract Command Item "," 3
  1388.     j = 0
  1389.     strextract CommandLine Command "|" j
  1390.     while not NULLSTR CommandLine
  1391.         if j != 0
  1392.             when quiet 10 call endhold
  1393.             holding()
  1394.             clearwhen quiet
  1395.         endif
  1396.         transmit CommandLine
  1397.         transmit "^M"
  1398.         j++
  1399.         strextract CommandLine Command "|" j
  1400.     endwhile
  1401.     strupdt Item "0" 0 1
  1402. endproc
  1403.  
  1404.  
  1405. #comment
  1406. *********************************************************************
  1407. * SENDSCRIPT()
  1408. * Called by dobbs()
  1409. * Calls getcommandprompt(), getotherprompt(), mailrunbox(),
  1410. * findstring(), makefullname()
  1411. * Executes a script file.  The script must return to the
  1412. * Main Command Prompt, or be the last item for that BBS.
  1413. *********************************************************************
  1414. #endcomment
  1415.  
  1416. proc sendscript
  1417. string ScriptName, BBSType
  1418.     getcommandprompt()
  1419.     profilerd MailRun BBS "BBSType" BBSType
  1420.     if !(findstring(BBSType, "PCBoard"))
  1421.         getotherprompt(GOTOMAIN)
  1422.     endif
  1423.     strextract ScriptName Item "," 3
  1424.     ScriptName = makefullname(MailRunDir, ScriptName)
  1425.     execute ScriptName
  1426.     strupdt Item "0" 0 1
  1427.     mailrunbox()
  1428. endproc
  1429.  
  1430.  
  1431. #comment
  1432. *********************************************************************
  1433. * LOGOFF()
  1434. * Called by dobbs()
  1435. * Logs off the current BBS.
  1436. *********************************************************************
  1437. #endcomment
  1438.  
  1439. proc logoff
  1440. integer i = 1
  1441.     if $CARRIER
  1442.         transmit "g^M"
  1443.     endif
  1444.     pause 5
  1445.     while $CARRIER && (i < 3)
  1446.         hangup
  1447.         pause 5
  1448.         i++
  1449.     endwhile
  1450. endproc
  1451.  
  1452.  
  1453. #comment
  1454. *********************************************************************
  1455. * MAILRUNBOX()
  1456. * Called by main(), sendscript()
  1457. * Draws the main MailRun dialog box.
  1458. *********************************************************************
  1459. #endcomment
  1460.  
  1461. proc mailrunbox
  1462. destroydlg
  1463. MainBoxTabs = "20,30,220,230,233,236,239,242"
  1464. HelpPage = 2
  1465. dialogbox 8 36 346 181 15 "MailRun" HELPID HelpPage
  1466.    groupbox 10 33 228 135 "Task List" shadow
  1467.    flistbox 15 52 218 102 TaskList MainBoxTabs single TaskItem
  1468.    text  15 153 49 8 left "# = permanent"
  1469.    text  76 153 49 8 left "ñ = temporary"
  1470.    text  140 153 33 8 left "! = error"
  1471.    text  182 153 53 8 left "@ = completed"
  1472.    groupbox 244 33 90 135 "Statistics" shadow
  1473.    text  248 55 62 8 right "BBSs in mailrun:"
  1474.    text  248 69 62 8 right "BBSs completed:"
  1475.    text  248 83 62 8 right "BBSs left to call:"
  1476.    text  248 97 62 8 right "Items in mailrun:"
  1477.    text  248 111 62 8 right "Items completed:"
  1478.    text  248 125 62 8 right "Item errors:"
  1479.    text  248 139 62 8 right "Items remaining:"
  1480.    text  248 153 62 8 right "Dialing Attempt:"
  1481.    vtext 314 55 16 9 left BBSTotal
  1482.    vtext 314 69 16 9 left BBSComplete
  1483.    vtext 314 83 16 9 left BBSRemaining
  1484.    vtext 314 97 16 9 left ItemTotal
  1485.    vtext 314 111 16 9 left ItemComplete
  1486.    vtext 314 125 16 9 left ItemError
  1487.    vtext 314 139 16 9 left ItemRemaining
  1488.    vtext 314 153 16 9 left AttemptNum
  1489.    text  102 14 74 8 right "The current mailrun is:"
  1490.    combobox 180 12 76 41 MailRunTrunc MailRunTrunc
  1491.    pushbutton 0 0 0 0 "          &t" normal default
  1492.    pushbutton 0 0 0 0 "          &u" normal
  1493.    pushbutton 0 0 0 0 "          &i" normal
  1494. enddialog
  1495. disable CTRL 170
  1496. endproc
  1497.  
  1498.  
  1499. #comment
  1500. *********************************************************************
  1501. * CAPTURESCREEN()
  1502. * Called by main(), holding(), sendmail(), getmail(),
  1503. * ulfile(), dlfile()
  1504. * Puts the current screen in the capture file.  Normally, the
  1505. * contents of a terminal screen are not placed in the capture
  1506. * file until they scroll off.  If a capture string is placed in
  1507. * a capture file, it will appear before the last screenfull of
  1508. * data.  This procedure is necessary to ensure that a capture
  1509. * string appears after all data that has already been received
  1510. * from the remote.
  1511. *********************************************************************
  1512. #endcomment
  1513.  
  1514. proc capturescreen
  1515. string RowString
  1516. integer Row, MaxRows, MaxCols
  1517.     fetch terminal rows MaxRows
  1518.     fetch terminal columns MaxCols
  1519.     for Row = 0 upto MaxRows
  1520.         termgets Row 0 RowString MaxCols
  1521.         capturestr RowString
  1522.         capturestr "`r`n"
  1523.     endfor
  1524.     termreset
  1525. endproc
  1526.         
  1527.